package com.deying.httplockserver.action;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;

import io.netty.handler.codec.http.HttpResponse;

@Controller
public class IndexAction {
	@Resource
	SimpMessagingTemplate template;
	@Value("${lock.port}")
	int lockPort;
	
	@RequestMapping("/")
	public String index(HttpServletResponse response){
		return "redirect:/index.html";
	}
/*	@RequestMapping("/test")
	@ResponseBody
	public Map<String,String> test(){
		
		ArrayNode tableData =  JsonNodeFactory.instance.arrayNode();
		ObjectNode tableItem = JsonNodeFactory.instance.objectNode();
		tableItem.put("name", "cao:1");
		tableItem.put("waitnum", 5);
		tableItem.put("locktime", System.currentTimeMillis());
		tableItem.put("maxlocktime", 100);
		
		tableData.add(tableItem);
		
		template.convertAndSend("/topic/status",tableData);
		return new HashMap<String,String>(){{
			put("name", "kao");
		}};
	}
*/	
	/**
	 * 控制台页面获得lock服务的端口
	 * @return
	 */
	
	@RequestMapping("/getPort")
	@ResponseBody
	public Integer getPort(){
		return lockPort;
	}
}
